package com.csyaonie.android;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.csyaonie.android.utils.ToastUtil;

import java.lang.reflect.Array;
import java.util.zip.Inflater;

public class DialogActivity extends AppCompatActivity {

    private Button btn_dialog1;
    private Button btn_dialog2;
    private Button btn_dialog3;
    private Button btn_dialog4;
    private Button btn_dialog5;
    private int sex= 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
        btn_dialog1=findViewById(R.id.btn_dialog1);
        btn_dialog2=findViewById(R.id.btn_dialog2);
        btn_dialog3=findViewById(R.id.btn_dialog3);
        btn_dialog4=findViewById(R.id.btn_dialog4);
        btn_dialog5=findViewById(R.id.btn_dialog5);

        Onclick onclick=new Onclick();
        btn_dialog1.setOnClickListener(onclick);
        btn_dialog2.setOnClickListener(onclick);
        btn_dialog3.setOnClickListener(onclick);
        btn_dialog4.setOnClickListener(onclick);
        btn_dialog5.setOnClickListener(onclick);

    }

    public class Onclick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_dialog1:
                    AlertDialog.Builder builder=new AlertDialog.Builder(DialogActivity.this);
                    builder.setTitle("提示").setMessage("are you ok").setPositiveButton("yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ToastUtil.showLong(DialogActivity.this,"fine");
                        }
                    }).setNegativeButton("no", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ToastUtil.showLong(DialogActivity.this,"ho no");
                        }
                    }).setIcon(R.drawable.user).show();
                    break;
                case R.id.btn_dialog2:
                    final String[] item=new String[]{"男","女"};
                    AlertDialog.Builder builder2=new AlertDialog.Builder(DialogActivity.this);
                    builder2.setTitle("提示").setItems(item, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ToastUtil.showLong(DialogActivity.this,item[which]);
                        }
                    }).show();
                    break;
                case R.id.btn_dialog3:
                    final String[] item3=new String[]{"男","女"};
                    AlertDialog.Builder builder3=new AlertDialog.Builder(DialogActivity.this);
                    builder3.setTitle("提示").setSingleChoiceItems(item3,getSex(), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ToastUtil.showLong(DialogActivity.this,item3[which]);
                            setSex(which);
                            dialog.dismiss();
                        }
                    }).setCancelable(false).show();
                    break;
                case R.id.btn_dialog4:
                    final String[] item4=new String[]{"男","女","未知"};
                    boolean[] selected=new boolean[]{false,false,true};
                    AlertDialog.Builder builder4=new AlertDialog.Builder(DialogActivity.this);
                    builder4.setTitle("提示").setMultiChoiceItems(item4, selected, new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                            ToastUtil.showLong(DialogActivity.this,item4[which]+":"+isChecked);
                        }
                    }).show();
                    break;
                case R.id.btn_dialog5:
                    AlertDialog.Builder builder5=new AlertDialog.Builder(DialogActivity.this);
                    View view= LayoutInflater.from(DialogActivity.this).inflate(R.layout.dialog_layout,null);
                    builder5.setView(view).setTitle("登录").show();
                    break;
            }
        }
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }
}